package com.wang.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @Classname AlipayConfig
 * @Description TODO
 * @Date 2024/9/14 10:07
 * @Created by pc
 */
@Component
public class AlipayConfig implements ApplicationRunner {
    // 应用id
    @Value("${alipay.appId}")
    private String appId;
    // 私钥
    @Value("${alipay.privateKey}")
    private String privateKey;
    // 支付宝公钥 公钥生成的支付宝公钥
    @Value("${alipay.publicKey}")
    private String publicKey;
    // 网关
    @Value("${alipay.gateway}")
    private String gateway;
    // 回调的接口 要用到内网穿透 主要是处理支付成功后的业务处理
    @Value("${alipay.notifyUrl}")
    private String notifyUrl;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        Factory.setOptions(getOptions());
        System.out.println("**********支付宝SDK初始化完成**********");
    }

    public Config getOptions(){
        Config config = new Config();
        config.protocol="https"; //协议
        config.gatewayHost=this.gateway; //网关
        config.signType="RSA2"; // 加密算法类型
        config.appId =  this.appId; // 应用id
        config.merchantPrivateKey = this.privateKey;//私钥
        config.alipayPublicKey = this.publicKey;// 支付宝公钥
        config.notifyUrl = this.notifyUrl;// 回调接口
        return config;
    }
}
